Type LQZone
	Global AllZones:TList = CreateList() 'of LQZone Instances
	Const VERSION:Short = 1
	Field name:String
	Field startScriptFile:String = ""
	Field startScriptFunc:String = ""
	
	Function Init()
		'get all the zone files in the zones directory, and put them in the allzones list...
		
		Local dir = ReadDir(ProjectFolder + "/Data/Zones")
			Repeat
				Local file:String = NextFile(dir)
				If file = "" Then Exit
				If file = "." Or file = ".." Then Continue
				If ExtractExt(file) = "dat" Then
					'this is a zone file (potentially, but we assume that it is...)
					LQZone.AllZones.AddLast(New LQZone.Load(ProjectFolder + "/Data/Zones/" + file))
				EndIf
			Forever
		CloseDir dir
				
		'put all the zone names & references (gadgetextra) into the appropriate comboboxes...
		For Local zone:LQZone = EachIn AllZones
			AddGadgetItem(ZoneCbbSelector,zone.name,0,-1,"",zone)
		Next
		If CountGadgetItems(ZoneCbbSelector) > 0 Then
			SelectGadgetItem(ZoneCbbSelector,0)
			ZoneCbbSelector_GA(ZoneCbbSelector,0)
		EndIf
	End Function
	
	Method Create:LQZone(newName:String)
		name = newName
		LQZone.AllZones.AddLast(Self)
		Return Self
	End Method
	
	Method Load:LQZone(filePathName:String)
		If Not FileType(filePathName) = 1 Then
			Print "Notice: Zone File ~q" + StripAll(filePathName) + "~q Not Found!"
			Return Self
		EndIf
		Local fileStream:TStream = LittleEndianStream(ReadFile(filePathName))
		If fileStream.ReadShort() <> LQZone.VERSION Then
			Error("Zone ~q" + StripAll(filePathName) + "~q Version Does Not Match LQUE Zone Version!")
		EndIf
		name = fileStream.ReadString(fileStream.ReadInt())
		startScriptFile = fileStream.ReadString(fileStream.ReadInt())
		startScriptFunc = fileStream.ReadString(fileStream.ReadInt())
		fileStream.Close()
		Return Self
	End Method
	
	Method Save(filePathName:String)
		Local fileStream:TStream = LittleEndianStream(WriteFile(filePathName))
		If Not fileStream Then Error("Could Not Save Zone File!")
		fileStream.WriteShort(LQZone.VERSION)
		fileStream.WriteInt(Len(name));fileStream.WriteString(name)
		fileStream.WriteInt(Len(startScriptFile));fileStream.WriteString(startScriptFile)
		fileStream.WriteInt(Len(startScriptFunc));fileStream.WriteString(startScriptFunc)
		fileStream.Close()
	End Method
End Type